package com.sf.controller;

import com.sf.common.JsonData;
import com.sf.dto.DeptLevelDto;
import com.sf.param.DeptParam;
import com.sf.service.RfDeptService;
import com.sf.service.RfTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/sys/dept")
@Slf4j
public class RfDeptController {

    @Resource
    private RfDeptService deptService;
    @Resource
    private RfTreeService deptTreeService;
    @RequestMapping("/toManager.json")
    public ModelAndView manager(){
        return new ModelAndView("dept");
    }

    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveDept(DeptParam deptParam) {

        System.out.println("来过");
        deptService.save(deptParam);
        return JsonData.success();
    }

    @RequestMapping("/tree.json")
    @ResponseBody
    public JsonData tree() {
        List<DeptLevelDto> dtoList = deptTreeService.deptTree();
          return JsonData.success(dtoList);
    }


}
